'use strict';

const Controller = require('egg').Controller;
const { ObjectId } = require('mongodb')
class DetailController extends Controller {
    async index() {
        const { ctx } = this;
        // console.log(ctx.params);
        try {
            var { id } = ctx.params;
            var db = this.app.mongodb;
            var res = await db.collection("IndexNew").find({ _id: ObjectId(id) }).toArray();
            ctx.body = {
                status: 200,
                res
            }
        } catch (err) {
            this.app.logger.error(err)
            ctx.status = 400;
            ctx.body = {
                status: 400,
                msg: "输入的id值参数不正确"
            }
            // console.log(err);
        }
    }
}

module.exports = DetailController;
